package com.example.callcenter.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.callcenter.entity.CallRecord;
import com.example.callcenter.dto.CallRecordDTO;
import com.example.callcenter.service.ICallRecordService;
import com.example.callcenter.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/record")
public class CallRecordController {

    @Autowired
    private ICallRecordService recordService;

    @PostMapping("/add")
    public ResultUtil addRecord(@RequestBody CallRecordDTO recordDTO) {
        recordService.saveRecord(recordDTO);
        return ResultUtil.success("记录保存成功");
    }

    @GetMapping("/task/{taskId}")
    public ResultUtil getByTaskId(
            @PathVariable Long taskId,
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {
        IPage<CallRecord> page = recordService.getByTaskId(taskId, pageNum, pageSize);
        return ResultUtil.success(page);
    }

    @GetMapping("/sales/{salesId}")
    public ResultUtil getBySalesId(
            @PathVariable Long salesId,
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {
        IPage<CallRecord> page = recordService.getBySalesId(salesId, pageNum, pageSize);
        return ResultUtil.success(page);
    }
}